
Vue.component2('a_1_0_1_1_0', {  
    template: `
        <div class="a_1_0_1_1_0_menu_bar" :key="refresh"  :style="'width:'+data.width">

            <div class="a_1_0_1_1_0_activity_item" v-for="(menu_id, index) in data.fast_menu" :key="index" @click="selectActivity(menu_id)" :class="{ a_1_0_1_1_0_active: menu_id == selectedActivity }"@mouseover="showSubMenu(menu_id)" @mouseleave="hideSubMenu(menu_id)">
                <span :class="data.menus[menu_id].menu_class"></span>
                <div class="a_1_0_1_1_0_sub_menu" v-if="menu_id==show_menu">
                    <div class="a_1_0_1_1_0_menu_item">
                        {{data.menus[menu_id].menu_name}}
                    </div>
                </div>
            </div>
        </div>
`,  
  data() {
      return {
        
        show_menu:"-1",
        selectedActivity:'0',
        refresh:"1",/*用来刷新组件*/
        data:{
            width:"100%",
            menus: {

        },
        fast_menu:[],//存放menus ids的数组 ids被转为整数 按照sort顺序排列
        show_flag:{}
        }
         
      };
  },
  methods: {
    showSubMenu(menu_id) {
        if (this.show_menu!=menu_id){
            this.show_menu=menu_id;
            // console.log(this.show_menu)
            this.refresh=this.refresh=="2"?"1":"2";
        }
    },
    hideSubMenu(menu_id) {
        this.show_menu=null;
        this.refresh=this.refresh=="2"?"1":"2";
    },
    selectActivity(id) {
        this.selectedActivity = id;
        for (let key in this.data.menus){

            // try{
                // console.log("run",`${this.data.menus[key].var_name}.set_show_index(${key})`)
                if(!(this.data.menus[key].init)){
                    this.data.menus[key].init=true;
                    lhp_run_func(`${this.data.menus[key].var_name}.set_show_index`,key)
                }
                // console.log("run",`${this.data.menus[key].var_name}.show_index_callback(${id})`)
                lhp_run_func(`${this.data.menus[key].var_name}.show_index_callback`,id)
                // }
            // catch{}
        }
        // console.log(`Selected activity: ${id}`);
    },

  },
  mounted:function(){
    //调用此函数刷新整个组件
    _this.refresh_func=function(){
        //创建菜单目录 快速查找数组
        _this.data.fast_menu=(Object.keys(_this.data.menus).map(Number)).sort();
        _this.refresh=_this.refresh=="2"?"1":"2";
    }

    
      //设置选项
      _this.data.set_menu=function(obj){
        /*
        var_name:全局变量 【window[var_name]】
        menu_id:选项id
        menu_name:选项名称
        menu_class:选项类
        menu_keys:选项快捷方式
        */
       let menu_id=obj.menu_id;
       let var_name=obj.var_name;
       let menu_name=obj.menu_name;
       let menu_class=obj.menu_class;
       let menu_keys=obj.menu_keys;
       let callback=obj.callback;
       //如果已经拥有这个目录 那么仅修改名称
       if (_this.data.menus.hasOwnProperty(menu_id)){
        _this.data.menus[menu_id]['menu_name']=menu_name;
        _this.data.menus[menu_id]['menu_class']=menu_class;
        _this.data.menus[menu_id]['menu_keys']=menu_keys;
        _this.data.menus[menu_id]['callback']=callback;
       }else{
        //如果没有拥有则新建一个
        _this.data.menus[menu_id]={
            "menu_name":menu_name,
            "menu_keys":menu_keys,
            "var_name":var_name,
            "menu_class":menu_class,
            "callback":callback,
        }
       }
       _this.refresh_func();//刷新组件
      },
      _this.data.选择=_this.selectActivity;
      //绑定快捷方式对象
      _this.data.bind_fast_obj=function(fast_obj){
        /*快捷方式通过全局 快捷方式对象进行调用*/
      }
  }
} 
);

